import { forBindEventThis } from '../../../../../global/direct/Func/eventBind';
import { event_check_operate } from '../../../../../global/element/Event/Func/event_check/Classes/cla_event_check_operate';
import { normalizeContainer } from '../../../../../global/element/Func';
import { quick_func_float_dataMana } from './cla_quick_func_float_dataMana';

const quick_func_float_operateTag = 'quick_func_float_operate';

/**
 * 事件 检测
 */
const event_check_func = new event_check_operate();

class quick_func_float_operate extends quick_func_float_dataMana {
  get [Symbol.toStringTag]() {
    return quick_func_float_operateTag;
  }

  constructor(props) {
    super(props);

    forBindEventThis(this);

    this.eventM.addEventListen(
      this.quick_func_float_border_dom,
      'mouseup',
      this.eventBind.quick_func_float_border_dom_mouse_up
    );

    this.eventM.addEventListen(
      this.quick_func_float_border_dom,
      'dblclick',
      this.eventBind.quick_func_float_border_dom_dbclick_self
    );
  }

  /**
   * 鼠标 抬起时 记录 当前 的 坐标信息
   */
  quick_func_float_border_dom_mouse_up() {
    this.set_cur_posi();
  }

  /**
   * 快速功能 点击 动画 显示 当前页面中的 快速功能
   */
  async quick_func_float_border_dom_dbclick_self() {
    let targetEl_id = this.get_targetEl_id_for_quick_func_float();
    if (
      targetEl_id == undefined ||
      (this.targetEl = normalizeContainer(targetEl_id)) == null
    ) {
      await this.no_single_func();
      return;
    }

    this.eventM.removeEventListen(
      this.quick_func_float_border_dom,
      'click',
      this.eventBind.quick_func_float_border_dom_dbclick_self
    );

    await this.open_view_container_func();

    this.eventM.addEventListen(
      window,
      'click',
      this.eventBind.window_white_space_click_self
    );
  }

  /**
   * 焦点元素 空白处 点击 取消 当前 操作
   * @param {MouseEvent} event
   */
  async window_white_space_click_self(event) {
    if (
      event_check_func
        .cur_event(event)
        .is_belone_itself(this.quick_func_float_border_dom).checked_result
    ) {
      return;
    }

    this.eventM.removeEventListen(
      window,
      'click',
      this.eventBind.window_white_space_click_self
    );

    await this.cancel_view_container_func();

    this.eventM.addEventListen(
      this.quick_func_float_border_dom,
      'click',
      this.eventBind.quick_func_float_border_dom_click_self
    );
  }
}

export { quick_func_float_operate };
